<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
</head>
<body>
<input type="text" id="username" ><input type="text" id="pwd"><button id="login">login</button>

<script>

    //将token存到cookie
    function setTokenToCookie(value) {
		var Days = 1; //此 cookie 将被保存 1 天
		var exp = new Date();
		exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
		document.cookie = "token=" + encodeURI(value) + ";expires=" + exp.toGMTString();
	}


    $(function(){
       $("#login").click(function(){
           $.post("login", {"username": $("#username").val(), "pwd": $("#pwd").val()}, function (res) {
                if (res.code === 0){
                    setTokenToCookie(res.msg);
                    window.location = "/index"
                }else{
                    alert(res.msg)
                }
           })
       })
    });
</script>
</body>
</html>